<template>
	<div>
		<view class="card order-info">
			<view class="cell e-m-b-20">
				<view class="cell-item">
					<text class="label blod">价格明细</text>
				</view>
				<view class="cell-item">
					<text class="label">商品总价</text>
					<text class="value">178,098.00 元</text>
				</view>
				<view class="cell-item">
					<text class="label">商品数量</text>
					<text class="value">{{ num }}</text>
				</view>
				<view class="cell-item">
					<text class="label">合计</text>
					<text class="value">48,098.00 元</text>
				</view>
			</view>

			<view class="line"></view>

			<view class="protol e-m-t-20">
				<checkbox-group name="" @change="agreeAllProtols = !agreeAllProtols">
					<view class="e-m-b-20">
						<label>
							<checkbox :checked="agreeAllProtols" 
								color="red" iconColor="white" activeBackgroundColor="red" />
							<text>
								我知悉并同意
							</text>
							<text @tap.stop="() => { }" class="red">《购买协议》</text>
							<text class="red">《购买须知》</text>
							<text>及</text>
							<text class="red">《风险揭露书》</text>
						</label>
					</view>
				</checkbox-group>
				<checkbox-group name="" @change="agreeNotSupportRefund = !agreeNotSupportRefund">
					<label>
						<checkbox :checked="agreeNotSupportRefund" color="red" iconColor="white"
							activeBackgroundColor="red" />
						<text>
							艺术品性质不支持7天无理由退换货，您一旦勾选，视为您同意不支持7天无理由退换货
						</text>
					</label>
				</checkbox-group>
			</view>
		</view>

		<view class="action-bar e-p-20">
			<view class="e-flex-x" style="align-items: center;">
				<view class="e-flex-1">
					<e-button size="normal" type="primary" color="#E4423B" shape="circle" :text="$t('确认抢购')"
						@click="confirm" :throttleTime="1000"></e-button>
				</view>
			</view>
		</view>


		<e-modal :show="showConfirmOrderModal" @cancel="showConfirmOrderModal = false" @confirm="confirmOrderAgain"
			title="请再次确认购买信息">
			<view class="content" style="width:90%">
				<view>
					<text>商品：云炉紫砂壶</text>
				</view>
				<view>
					<text>数量：3</text>
				</view>
				<view><text>单价：178,098.00 元</text></view>
				<view>
					<text>金额：534,294.00 元</text>
				</view>
			</view>
		</e-modal>
	</div>
</template>

<script setup>
	import {
		ref
	} from "vue"
	import {
		routeJump
	} from "@/common/utils"

	// refs 
	const agreeAllProtols = ref(false) //用户协议
	const agreeNotSupportRefund = ref(false) //不支持7天无理由退换
	const showConfirmOrderModal = ref(false) //再次确认订单信息

	const num = ref(1)


	//methods
	const confirm = () => {
		if (!agreeAllProtols.value) {
			uni.showToast({
				title: "请同意购买协议",
				icon: "none"
			})
			return
		}

		if (!agreeNotSupportRefund.value) {
			uni.showToast({
				title: "请同意不支持7天无理由退换货",
				icon: "none"
			})
			return
		}
		showConfirmOrderModal.value = true
	}

	const confirmOrderAgain = () => {
		showConfirmOrderModal.value = false
		routeJump("./success", "navigateTo")
	}


	// 修改数量
	const add = () => {
		changeNum(num.value + 1)
	}

	const sub = () => {
		changeNum(num.value - 1)
	}


	const changeNumWithInput = e => {
		console.log(e)
		changeNum(e.detail.value)
	}

	const changeNum = (val) => {
		console.log("val", val)
		let _val = Number(val) * 1

		if (_val < 1) {
			_val = 1
		}
		num.value = _val
	}

	// end 修改数量
</script>

<style lang="scss" scoped>
	.card {
		background: rgba(255, 255, 255, 1);
		padding: 20rpx;
		border-radius: 20rpx;
		margin: 20rpx;
	}

	.info {
		.cover {
			width: 200rpx;
			height: 200rpx;
			border-radius: 20rpx;
			background-color: #ddd;
		}

		.content {
			.title {
				width: 160rpx;
				height: 44rpx;
				font-family: PingFangSC, PingFang SC;
				font-weight: 600;
				font-size: 32rpx;
				color: #333333;
				line-height: 44rpx;
				text-align: left;
				font-style: normal;
				text-overflow: ellipsis;
			}


		}
	}

	.price {
		width: 116rpx;
		height: 50rpx;
		font-family: PingFangSC, PingFang SC;
		font-weight: 600;
		font-size: 24rpx;
		color: #E4423B;
		line-height: 34rpx;
		text-align: left;
		font-style: normal;

		&.lg {
			font-size: 32rpx;
		}

		&.xl {
			font-weight: 500;
			font-size: 36rpx;
			color: #F5222D;
			line-height: 50rpx;
		}
	}

	.order-info {}

	.blod {
		font-weight: 600;
	}

	.cell {
		.cell-item {
			display: flex;
			flex-direction: row;
			align-items: center;
			justify-content: space-between;
			min-height: 72rpx;
			line-height: 72rpx;
		}
	}

	.line {
		height: 1rpx;
		background-color: #ddd;
		transform: scaleY(0.5);
	}

	.protol {
		.red {
			color: #E4423B;
		}
	}

	.action-bar {
		position: fixed;
		bottom: 0;
		width: 100vw;
		z-index: $z-index-high;
		background-color: #ffffff;
	}

	.num-check-box {
		border: 1rpx solid #ccc;
		border-radius: 10rpx;
		box-sizing: border-box;

		button {
			display: block;
			width: 56rpx;
			height: 56rpx;
			line-height: 56rpx;
			font-size: 36rpx;
		}

		input {
			width: 4rem;
			line-height: 56rpx;
			font-size: 32rpx;
			border-left: 1rpx solid #ccc;
			border-right: 1rpx solid #ccc;
			padding: 0 20rpx;
			text-align: center;
		}
	}
</style>